<template>
  <div class="nav-menu">
    <div class="logo">
      <img class="img" src="@/assets/img/logo.svg" alt="logo" />
      <span class="title" v-if="!Collapse">Vue3+TS</span>
    </div>
    <!-- 菜单 -->
    <el-menu
      class="el-menu-vertical"
      background-color="#001529"
      active-text-color="#0a60bd"
      text-color="#fff"
      :unique-opened="false"
      :collapse="Collapse"
      :default-active="currentPath"
      :router="true"
    >
      <!-- 一级菜单 -->
      <template v-for="item in mainstore.menuList" :key="item.id">
        <el-sub-menu :index="item.id + ''">
          <template #title>
            <el-icon><i-ep-location /></el-icon>
            <span>{{ item.name }}</span>
          </template>
          <!-- 二级菜单 -->
          <template v-for="subItem in item.children" :key="subItem.id">
            <el-menu-item :index="subItem.path">
              <template #title>
                <el-icon><i-ep-menu /></el-icon>
                <span>{{ subItem.name }}</span>
              </template>
            </el-menu-item>
          </template>
        </el-sub-menu>
      </template>
    </el-menu>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed } from "vue"
import { mainStore } from "@/stores/modules/main"
import { useRoute } from "vue-router"

export default defineComponent({
  components: {},
  props: {
    Collapse: {
      type: Boolean,
      default: false
    }
  },
  setup() {
    const mainstore = mainStore()

    // 当前路径
    const currentPath = computed(() => {
      const route = useRoute()
      return route.path
    })

    return {
      mainstore,
      currentPath
    }
  }
})
</script>

<style scoped lang="less">
.nav-menu {
  height: 100%;

  .logo {
    display: flex;
    height: 28px;
    padding: 12px 10px 8px 10px;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;

    .img {
      height: 100%;
      margin: 0 10px;
    }

    .title {
      font-size: 16px;
      font-weight: 700;
      color: white;
    }
  }

  .el-menu {
    border-right: none;
  }

  // 目录
  .el-sub-menu {
    background-color: #001529 !important;
    // 二级菜单 ( 默认背景 )
    .el-menu-item {
      padding-left: 50px !important;
      background-color: #0c2135 !important;
    }
  }

  // 鼠标移入项高亮颜色
  .el-menu-item:hover {
    color: #fff !important; // 菜单
  }

  .el-menu-item.is-active {
    // 选中项的文本颜色
    color: #fff !important;
    // 选中项的背景颜色
    background-color: #0a60bd !important;
  }
}

.el-menu-vertical:not(.el-menu--collapse) {
  width: 100%;
  height: calc(100% - 68px);
}
</style>
